#!/bin/bash

# 切换到脚本所在目录
cd "$(dirname "$0")"

echo "================================================"
echo "    建党在线系统 - Docker 日志查看"
echo "================================================"
echo ""

# 检测 Docker Compose 命令
if command -v docker &> /dev/null && docker compose version &> /dev/null 2>&1; then
    DOCKER_COMPOSE="docker compose"
elif command -v docker-compose &> /dev/null; then
    DOCKER_COMPOSE="docker-compose"
else
    echo "❌ 错误: 未找到 Docker Compose"
    exit 1
fi

echo "选择要查看的服务日志："
echo "  1) 全部服务"
echo "  2) 后端服务"
echo "  3) 管理端"
echo "  4) 用户端"
echo ""
read -p "请选择 (1-4): " choice

case $choice in
    1)
        echo ""
        echo "📋 查看全部服务日志 (Ctrl+C 退出)..."
        echo ""
        $DOCKER_COMPOSE logs -f
        ;;
    2)
        echo ""
        echo "📋 查看后端服务日志 (Ctrl+C 退出)..."
        echo ""
        $DOCKER_COMPOSE logs -f backend
        ;;
    3)
        echo ""
        echo "📋 查看管理端日志 (Ctrl+C 退出)..."
        echo ""
        $DOCKER_COMPOSE logs -f client
        ;;
    4)
        echo ""
        echo "📋 查看用户端日志 (Ctrl+C 退出)..."
        echo ""
        $DOCKER_COMPOSE logs -f front
        ;;
    *)
        echo ""
        echo "❌ 无效选择"
        echo ""
        ;;
esac

